// 云函数入口文件
const cloud = require('wx-server-sdk')
const {
  dateTool
} = require('./dateTool')

const tools = {
  dateTool,
}

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
}) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const {
    action
  } = event
  const arr = action.split(".")
  if (!arr || arr.length < 2) return "action error"

  const toolName = arr[0],
    funcName = arr[1]
  const tool = tools[toolName]
  tool.data = event
  return tool[funcName]()
}